package com.mjh.zhujianju.controller.visit;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.livew.framework.base.controller.BaseController;
import com.livew.framework.base.service.BaseService;
import com.livew.framework.exception.XTBusinessException;
import com.livew.framework.page.PagedResult;
import com.livew.framework.pojo.AjaxResult;
import com.mjh.zhujianju.enums.SupervisionTypeEnum;
import com.mjh.zhujianju.model.supervise.SupervisionEO;
import com.mjh.zhujianju.service.supervise.SupervisionService;
import com.mjh.zhujianju.service.visit.VisitUserService;
import com.mjh.zhujianju.vo.supervision.SupervisionVO;
import com.mjh.zhujianju.vo.visit.VisitUserVO;

@Controller
@RequestMapping("visit/letter")
public class LetterController extends BaseController<SupervisionEO>{

	@Resource
	private SupervisionService supervisionService;
	
	@Resource
	private VisitUserService visitUserService;
	
	@Override
	protected BaseService<SupervisionEO> getService() {
		
		return supervisionService;
	}

	
	/**
	 * 分页
	 * 
	 * @Description:
	 * @return
	 * @author wt1293
	 * @date 2018年8月9日下午8:08:53
	 *
	 */
	@RequestMapping(value = "getPage", method = RequestMethod.POST)
	@ResponseBody
	public AjaxResult getPage(SupervisionVO vo) {
		
		PagedResult<SupervisionVO> list = supervisionService.getLetterPage(vo);
		return AjaxResult.getResult(list);
	}

	
	/**
	 * 根据手机号，姓名，身份证号 查询
	 * @param user
	 * @return
	 */
	@RequestMapping(value = "getVisitUserList", method = RequestMethod.POST)
	@ResponseBody
	public AjaxResult getVisitUserList(VisitUserVO user) {
//		if(XTStringUtils.isEmpty(user.getRemark())) {
//			return AjaxResult.getResult(null);
//		}
	 List<VisitUserVO> list= visitUserService.getVisitUserList(user.getRemark());
	 return AjaxResult.getResult(list);
	}
	
	
	
	/**
	 * 保存
	 * 
	 * @Description:
	 * @param vo
	 * @return
	 * @author wt1293
	 * @date 2018年8月21日下午1:46:27
	 *
	 */
	@RequestMapping(value = "saveInfo", method = RequestMethod.POST)
	@ResponseBody
	public AjaxResult saveInfo(SupervisionVO vo) {
		if (vo == null) {
			return AjaxResult.getResult(Boolean.FALSE, "参数错误");
		}
		try {
			vo.setType(SupervisionTypeEnum.visit.getCode());
			supervisionService.saveInfo(vo);
		} catch (XTBusinessException e) {
			e.printStackTrace();
			return AjaxResult.getResult(Boolean.FALSE, e.getMessage());
		}
		return AjaxResult.getResult(Boolean.TRUE, "保存成功");
	}
	
	
	
	/**
	 * 保存
	 * 
	 * @Description:
	 * @param vo
	 * @return
	 * @author wt1293
	 * @date 2018年8月21日下午1:46:27
	 *
	 */
	@RequestMapping(value = "updateInfo", method = RequestMethod.POST)
	@ResponseBody
	public AjaxResult  updateInfo(SupervisionVO vo) {
		if (vo == null) {
			return AjaxResult.getResult(Boolean.FALSE, "参数错误");
		}
		try {
			vo.setType(SupervisionTypeEnum.visit.getCode());
			supervisionService.updateInfo(vo);
		} catch (XTBusinessException e) {
			e.printStackTrace();
			return AjaxResult.getResult(Boolean.FALSE, e.getMessage());
		}
		return AjaxResult.getResult(Boolean.TRUE, "保存成功");
	}
	
	
	/**
	 * 获取详情
	 */
	public AjaxResult findById(@PathVariable("id") Long id) {
		if (id == null) {
			return AjaxResult.getResult(Boolean.FALSE, "参数错误");
		}
		SupervisionVO t = null;
		try {
			t = this.supervisionService.getInfo(id);
		} catch (XTBusinessException e) {
			e.printStackTrace();
			return AjaxResult.getResult(Boolean.FALSE, e.getMessage());
		}
		return AjaxResult.getResult(t);
	}


}

